<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Index extends Controller {

    public function action_index(){
        $view = View::factory('index');
        
        $gender = "m";
        
        if($gender=="m"){
            $nicegender = "Sir";
        } else {
            $nicegender = "Madam";
        }

        if(date("h") < 6 || date("h") > 18) {
                $greeting = "Good evening";
        } elseif(date("h") >= 6 && date("h") <= 11) {
                $greeting = "Good morning";
        } else {
                $greeting = "Good afternoon";
        }

        $view->title = __($greeting).", ".__($nicegender);

        $view->date =  __('The date is');
        $view->date .= strftime(' %e %B %Y',mktime(0,0,0,date('m'),date('d'),date('Y')));
        $view->date .= ", ".__('which is a');
        $view->date .= strftime(' %A', mktime(0,0,0,date('m'),date('d'),date('Y')));
        $view->date .= ".";

        // fetch the blocks, and pass them to the view
        $view->blocks = Array();

        $query = DB::query(Database::SELECT, 'SELECT ID FROM blocks');
        $blocks = $query->execute();

        for($i=0;$i<$blocks->count();$i++){
            $currentBlock = $blocks->current();

            $view->blocks[$i] = array(
                'ID' => $currentBlock['ID'],
            );

            $blocks->next();
        }

        $this->request->response = $view;
    }

}